import axios from 'axios'
import * as actionTypes from './actionTypes'

const changeHomeData = (result) => ({
    type: actionTypes.CHANGE_HOME_DATA,
    articleList: result.articleList,
    topicList: result.topicList
})

const LoadMore = (data) => ({
    type: actionTypes.LOAD_MORE,
    data
})

export const getHomeInfo = () => {
    return (dispatch) => {
        axios.get('https://www.easy-mock.com/mock/5aeafcbb671cac5c2b7aa069/home')
            .then(res => {
                const data = res.data.data
                dispatch(changeHomeData(data))
            })
            .catch(err => {
                console.log(err)
            })
    }
}

export const getLoadMore = () => {
    return (dispatch) => {
        axios.get('https://www.easy-mock.com/mock/5aeafcbb671cac5c2b7aa069/home')
            .then(res => {
                const data = res.data.data
                dispatch(LoadMore(data))
            })
            .catch(err => {
                console.log(err)
            })
    }
}

export const toggleTopShow = (show) => ({
    type:actionTypes.TOGGLE_SCROLL_TOP,
    show
})